<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>尾款详情</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
    <style type="text/css">
        thead th, tbody td {
            padding-left: 8px !important;
            padding-right: 8px !important;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" action="${ctx}/moneyManagement/tailParagraph/tailParagraphList.do"
                              id="myForm" method="post">
                            <input type="hidden" name="memberId" id="memberId" value="${memberId}"/>
                            <input type="hidden" name="businessId" id="businessId" value="${businessId}"/>
                        </form>
                        <div class="my-act-list-content">
                            <div class="cl">
                                <table class="layui-table">
                                    <tbody>
                                    <c:forEach var="wao" items="${list}" varStatus="st">
                                        <tr>
                                        <td colspan="6">
                                            <div class="tc">

                                                <div class="layui-input-inline" style="font-size:18px;">
                                                    <c:choose>
                                                        <c:when test="${wao.progress == 1}">
                                                            <font color="green">提交申请</font>
                                                        </c:when>
                                                        <c:when test="${wao.progress == 2}">
                                                            <font
                                                                    <c:if test="${wao.state == 1}">color="green"</c:if>
                                                                    <c:if test="${wao.state == 0}">color="red"</c:if>
                                                            >客服处理</font>

                                                        </c:when>
                                                        <c:when test="${wao.progress == 3}">
                                                            <font
                                                                    <c:if test="${wao.state == 1}">color="green"</c:if>
                                                                    <c:if test="${wao.state == 0}">color="red"</c:if>
                                                            >客户确认</font>

                                                        </c:when>
                                                        <c:when test="${wao.progress == 4}">
                                                            <font
                                                                    <c:if test="${wao.state == 1}">color="green"</c:if>
                                                                    <c:if test="${wao.state == 0}">color="red"</c:if>
                                                            >财务打款</font>
                                                        </c:when>
                                                    </c:choose>
                                                </div>
                                            </div>
                                            <c:if test="${wao.state !=3}">
                                                <div class="tc"></div>
                                                <div class="tc">
                                                    <div class="layui-input-inline">
                                                        <fmt:formatDate value="${wao.createDate}"
                                                                        pattern="yyyy-MM-dd HH:mm:ss"/>
                                                    </div>
                                                </div>
                                                <c:if test="${wao.progress == 1}">
                                                    <div class="tc">
                                                        <label class="search-form-lable"><strong>备注：</strong></label>
                                                        <div class="layui-input-inline">
                                                                ${wao.noteMessage}
                                                        </div>
                                                    </div>
                                                    <c:if test="${wao.accessoryUrl !=null && wao.accessoryUrl!=''}">
                                                        <div class="tc">
                                                            <label class="search-form-lable"><strong>附件：</strong></label>
                                                            <div class="layui-input-inline">
                                                                <a target="_blank" style="color: green" href="${wao.accessoryUrl}">下载附件</a>
                                                            </div>
                                                        </div>
                                                    </c:if>
                                                </c:if>
                                                <c:if test="${wao.progress != 1}">
                                                    <div class="tc">
                                                        <label class="search-form-lable"><strong>结果：</strong></label>
                                                        <span class="layui-input-inline">

                                                        <c:choose>
                                                            <c:when test="${ wao.progress == 2}">
                                                                <c:if test="${wao.state == 0}">
                                                                    审核拒绝
                                                                </c:if>
                                                                <c:if test="${wao.state == 1}">
                                                                    审核通过
                                                                </c:if>
                                                            </c:when>
                                                            <c:when test="${ wao.progress == 3}">
                                                                <c:if test="${wao.state == 0}">
                                                                    提出异议，再次提交申请
                                                                </c:if>
                                                                <c:if test="${wao.state == 1}">
                                                                    确认通过
                                                                </c:if>
                                                            </c:when>
                                                            <c:when test="${ wao.progress == 4}">
                                                                <c:if test="${wao.state == 0}">
                                                                    未处理
                                                                </c:if>
                                                                <c:if test="${wao.state == 1}">
                                                                    已打款，请注意查收
                                                                </c:if>
                                                            </c:when>
                                                        </c:choose>

                                                        </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                        <c:if test="${wao.progress == 2 && wao.state == 1}">
                                                            <label class="search-form-lable"><strong>尾款金额：</strong></label>
                                                            <span class="layui-input-inline">
                                                             <fmt:formatNumber pattern="0.00" value="${wao.payment}"/>元
                                                        </span>
                                                        </c:if>
                                                    </div>
                                                    <c:if test="${wao.progress == 2 || (wao.progress == 3 && wao.state == 0)}">

                                                        <div class="tc">
                                                            <label class="search-form-lable"><strong>备注：</strong></label>
                                                            <div class="layui-input-inline">
                                                                    ${wao.noteMessage}
                                                            </div>
                                                        </div>
                                                    </c:if>
                                                    <c:if test="${wao.progress == 2 || wao.progress == 3 }">
                                                        <c:if test="${wao.accessoryUrl !=null && wao.accessoryUrl!=''}">
                                                            <div class="tc">
                                                                <label class="search-form-lable"><strong>附件：</strong></label>
                                                                <div class="layui-input-inline">
                                                                    <a target="_blank" style="color: green" href="${wao.accessoryUrl}">下载附件</a>
                                                                </div>
                                                            </div>
                                                        </c:if>
                                                    </c:if>
                                                </c:if>
                                            </c:if>
                                        </td>
                                        <c:if test="${st.last}">
                                            <c:choose>
                                                <c:when test="${ wao.progress == 2}">
                                                    <td>
                                                        <div class="tc">
                                                            <div class="layui-input-inline">

                                                                <a class="layui-btn layui-btn-danger"
                                                                   href="javascript:passTailParagraph('${wao.id}','${wao.wId}',2,1)">通过</a>
                                                                <a class="layui-btn layui-btn-danger"
                                                                   href="javascript:refusedTailParagraph('${wao.id}','${wao.wId}',2,0)">拒绝</a>

                                                            </div>
                                                        </div>
                                                    </td>
                                                </c:when>
                                                <c:when test="${ wao.progress == 4 && wao.state== 3}">
                                                    <td>
                                                        <div class="tc">
                                                            <div class="layui-input-inline">

                                                                <a class="layui-btn layui-btn-danger"
                                                                   href="javascript:emittanceTailParagraph('${wao.id}','${wao.wId}',4,1)">打款</a>

                                                            </div>
                                                        </div>
                                                    </td>
                                                </c:when>
                                            </c:choose>
                                            </tr>
                                        </c:if>
                                        </tr>
                                        <c:if test="${!st.last}">
                                            <tr>
                                                <td colspan="6" style="font-color:green;">
                                                    <div class="f18 tc">|</div>
                                                    <div class="f18 tc">|</div>
                                                    <div class="f18 tc">|</div>
                                                    <div class="f18 tc">V</div>
                                                </td>
                                            </tr>
                                        </c:if>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item"></div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>


    <div id="passittailParagraphDiv" style="padding: 0px 10px">
        <div>
            <form id="passittailParagraphForm" class="layui-form mt20" method="post"
                  action="${ctx}/moneyManagement/tailParagraph/editTailParagraph.do">
                <input type="hidden" name="id" value=""/>
                <input type="hidden" name="wId" value=""/>
                <input type="hidden" name="progress" value="">
                <input type="hidden" name="state" value="">
                <div class="cl">
                    <table class="layui-table">
                        <tbody>
                        <tr>
                            <td><label class="layui-form-label">应付尾款<span class="f-verify-red">*</span>：</label>
                                <div class="layui-input-inline">
                                    <input type="number" min="1" style="width:250px;" name="payment" autocomplete="off"
                                           class="layui-input payment"
                                           lay-verify="payment" placeholder="请输入尾款金额" value="">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><label class="layui-form-label">备注</label>
                                <div class="layui-input-block">
                                <textarea name="noteMessage" style="width: 250px;"
                                          placeholder="请填写备注" class="layui-textarea"></textarea>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><label class="layui-form-label">
<%--                                <a id="sel_accessory_img" style="color: green"
                                   href="javascript:uploadccessory()">上传附件</a>--%>
                                    附件
                            </label>
                                <div class="cover-content">
                                    <div class="layui-input-inline">
                                        <input type="text" id="accessoryUrl" name="accessoryUrl" class="layui-input"   value="" readonly/>
                                    </div>
                                    <div class="u-single-upload">
                                        <input type="file"class="u-single-file" id="accessory" name="accessory"> <span class="u-single-upload-icon">+上传</span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </form>
        </div>
    </div>


    <div id="refusedittailParagraphDiv" style="padding: 0px 10px">
        <div>
            <form id="refusedittailParagraphForm" class="layui-form mt20" method="post"
                  action="${ctx}/moneyManagement/tailParagraph/editTailParagraph.do">
                <input type="hidden" name="id" value=""/>
                <input type="hidden" name="wId" value=""/>
                <input type="hidden" name="progress" value="">
                <input type="hidden" name="state" value="">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注<span style="color: red;">*</span></label>
                    <div class="layui-input-block">
                        <textarea name="noteMessage" lay-verify="" style="width: 250px;"
                                  placeholder="请填写审核备注" class="layui-textarea"></textarea>
                    </div>
                </div>
            </form>
        </div>
    </div>


</div>
<script type="text/javascript" src="${ctxStatic}/cos-js-sdk-v4-master/dist/cos-js-sdk-v4.js"></script>
<script type="text/javascript" src="${ctx}/script/upload/cosUploadUtil.js"></script>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">

    $(function () {

        var cosUtil = new CosUtil({
            mainFolder: "/cert/",
            bucketType: 1,// 0: 图片, 1: 文件
            insertOnly: 0,//insertOnly==0 表示允许覆盖文件 1表示不允许
            onProgress: function (file, ret) {

            }
        }).init();

        txz.initHeader({
            nav: [{
                name: '资金管理',
                curr: true
            }, {
                name: '${event.name}'
            }, {
                name: '提现详情',
                curr: true
            }],
            info: '',
            btns: [{
                name: '返回',
                href: 'javascript:history.go(-1)',
                icon: 'back'
            }]
        });

        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });




        $('#accessory').change(function () {
            var payment = $("#passittailParagraphDiv #passittailParagraphForm [name=payment]").val();
            var wpId= $("#passittailParagraphDiv #passittailParagraphForm [name=id]").val();
            payment = $.trim(payment);
            if (!util.isValid(payment)){
                util.layerMsgError('请先填写尾款金额')
                return;
            }
            var files = document.getElementById("accessory").files;
            var newFiles = new Array(1);
            newFiles[0] = files[0];
            var fileName = files[0].name;

            if (fileName.lastIndexOf(".rar") < 0&&fileName.lastIndexOf(".zip")<0) {
                util.layerMsgError("请正确上传.rar/.zip格式的附件");
                return;
            }
            cosUtil.opt.mainFolder = cosUtil.opt.mainFolder +  wpId + "/";

            // 查看证书是否已经存在
            cosUtil.opt.onSuccess = function (file, result) {
                layer.confirm('该文件已经存在, 确定要覆盖吗?', { icon: 3, title:'提示' }, function(index){
                    layer.close(index);
                    uploadCert(newFiles);
                });
            };
            cosUtil.opt.onFailure = function (file, result) {
                uploadCert(newFiles);
            }
            cosUtil.getFileStat(newFiles[0]);

        });

        function uploadCert(newFiles) {
            var loadIndex = top.layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            // 上传附件
            cosUtil.opt.onSuccess = function (file, result) {
                top.layer.close(loadIndex);
                console.log(result.data)
                $("#accessoryUrl").val(result.data.access_url);
                util.layerMsgSuccess("附件上传成功");
                console.log(result);
            };
            cosUtil.opt.onFailure = function (file, result) {
                util.layerMsgError("附件上传失败");
                console.log(result);
            }
            cosUtil.uploadFile(newFiles);
        }
    })




    /**
     * 通过尾款提现
     * @param wId,progress,state
     */
    function passTailParagraph(id, wId, progress, state) {

        $("#passittailParagraphDiv #passittailParagraphForm").show();
        $("#passittailParagraphDiv #passittailParagraphForm [name=id]").val(id);
        $("#passittailParagraphDiv #passittailParagraphForm [name=wId]").val(wId);
        $("#passittailParagraphDiv #passittailParagraphForm [name=progress]").val(progress);
        $("#passittailParagraphDiv #passittailParagraphForm [name=state]").val(state);
        var lock = false //默认未锁定
        var checkIndex = layer.open({
            type: 1,
            area: ['460px', '350px'],
            title: '审核',
            content: $("#passittailParagraphDiv"),
            btn: ['确定', '取消'],
            yes: function () {
                var payment = $("#passittailParagraphDiv #passittailParagraphForm [name=payment]").val();
                if (payment < 0.01) {
                    layer.msg('尾款金额不能小于0.01', {time: 2000, icon: 0, title: '系统提示'});
                    return;
                }
                if (!lock) {
                    lock=true;
                    $.post($("#passittailParagraphDiv #passittailParagraphForm").attr('action'),
                        $("#passittailParagraphDiv #passittailParagraphForm").serialize(), function (res) {
                            if (res.success) {
                                layer.msg('审核成功', {title: '审核通知', icon: 1, time: 2000}, function () {
                                    window.location.reload();
                                });
                            } else {
                                layer.msg(res.description, {title: '审核通知', icon: 2, time: 2000});
                            }
                        });
                }
            },
            end: function () {//取消按钮
                $("#passittailParagraphDiv #passittailParagraphForm [name=id]").val('');
                $("#passittailParagraphDiv #passittailParagraphForm [name=payment]").val('');
                $("#passittailParagraphDiv #passittailParagraphForm [name=noteMessage]").val('');
                $("#passittailParagraphDiv #passittailParagraphForm [name=wId]").val('');
                $("#passittailParagraphDiv #passittailParagraphForm [name=progress]").val('');
                $("#passittailParagraphDiv #passittailParagraphForm [name=state]").val('');
                $("#passittailParagraphDiv #passittailParagraphForm [name=accessoryUrl]").val('');
                layer.close(checkIndex);
            }
        });
    }


    /**
     * 拒绝尾款提现
     * @param wId,progress,state
     */
    function refusedTailParagraph(id, wId, progress, state) {

        $("#refusedittailParagraphDiv #refusedittailParagraphForm").show();
        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=id]").val(id);
        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=wId]").val(wId);
        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=progress]").val(progress);
        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=state]").val(state);
        layer.confirm('确定要审核拒绝提现吗？', {icon: 3, title: '审核拒绝提示'}, function (index) {
            var lock = false //默认未锁定
            layer.open({
                type: 1,
                area: ['400px', '250px'],
                title: '审核',
                content: $("#refusedittailParagraphDiv"),
                btn: ['确定', '取消'],
                yes: function () { // 确定按钮

                    var checkRemark = $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=noteMessage]").val();
                    if (checkRemark.trim() == '') {
                        layer.msg('请填写审核备注', {time: 2000, icon: 0, title: '系统提示'});
                        return;
                    }
                    if (!lock) {
                        lock = true;
                        $.post($("#refusedittailParagraphDiv #refusedittailParagraphForm").attr('action'),
                            $("#refusedittailParagraphDiv #refusedittailParagraphForm").serialize(), function (res) {

                                if (res.success) {
                                    layer.msg('审核拒绝成功', {title: '审核通知', icon: 1, time: 2000}, function () {
                                        window.location.reload();
                                    });
                                } else {
                                    layer.msg(res.description, {title: '审核通知', icon: 2, time: 2000});
                                }
                            });
                    }
                },
                btn2: function () {// 取消按钮
                    $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=noteMessage]").val("");
                    layer.close(index);
                }
            });
        });

    }


    /**
     * 打款
     * @param wId,progress,state
     */
    function emittanceTailParagraph(id, wId, progress, state) {

        $.post("${ctx}/moneyManagement/tailParagraph/editTailParagraph.do", {
            id: id,
            wId: wId,
            progress: progress,
            state: state
        }, function (data) {
            setTimeout(function () {
                if (data.success) {
                    layer.msg('打款成功', {title: '打款通知', icon: 1, time: 2000}, function () {
                        window.location.reload();
                    });
                } else {
                    layer.msg(data.description, {title: '打款通知', icon: 2, time: 2000});
                }
            }, 200);
        })
    }

    /**
     * 上传附件
     * @param wId,progress,state
     */
    function uploadccessory() {
        var id = $("#passittailParagraphDiv #passittailParagraphForm [name=id]").val();
        txz.openSelImg({
            min: 1,
            max: 1,
            info: '建议尺寸：800x450',
            type: '<%=TargetType.FINALPAYMENT.getCode()%>',
            cb: function (imgs) {
                var accessoryUrl = imgs[0].path;
                $.post("${ctx}/moneyManagement/tailParagraph/uploadccessory.do", {
                    id: id,
                    accessoryUrl: accessoryUrl
                }, function (data) {
                    setTimeout(function () {
                        if (data.success) {
                            layer.msg('附件上传成功', {title: '附件上传通知', icon: 1, time: 2000}, function () {

                                $('#sel_accessory_img').attr('href', accessoryUrl);

                                $("#sel_accessory_img").text('下载附件');

                                //window.location.reload();
                            });
                        } else {
                            layer.msg(data.description, {title: '附件上传通知', icon: 2, time: 2000});
                        }
                    }, 200);
                })
            }
        })
    }
</script>
</body>
</html>